package com.qj.platform.pay.core.service;

import com.qj.platform.pay.commons.execption.SdsCodeDefinition;
import com.qj.platform.pay.commons.execption.SdsException;
import com.qj.platform.pay.core.dao.OperatorDao;
import com.qj.platform.pay.core.domain.Operator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OperatorService {


    @Autowired
    private OperatorDao operatorDao;

    public Operator getUserByUserName(String username){
        return operatorDao.getUserByUserName(username);
    }

    public void addUser(String userName,String password,String nickName){
        Operator user=getUserByUserName(userName);
        if(user!=null){
            throw new SdsException(SdsCodeDefinition.ILLEGAL_ARGUMENT_VALUE,"该用户名已存在");
        }
        operatorDao.addUser(userName, password, nickName);
    }

    public void updateUser(String id,String password,String nickName){
        operatorDao.updateUser(id, password, nickName);
    }

    public Operator login(String name,String pwd){
        Operator operator=getUserByUserName(name);
        if(operator==null||!operator.getPassword().equals(pwd)){
            throw new SdsException(SdsCodeDefinition.ILLEGAL_ARGUMENT_VALUE,"用户名或密码不正确");
        }
        return operator;
    }

}
